package com.burgeon.backend.SHOPBACKEND.rest.marketing;
/**
 * 创建智能营销记录
 */
import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.HashMap;

public class createMarketingVO extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public createMarketingVO(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public String getData(String name,String begDate, String endDate, String putQty,String getQty) throws Exception {
        String url = "http://" + ip + "/servlets/binserv/Rest";

        String str = RESULT(Data(name,begDate,endDate,putQty,getQty), url);

        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message= new JSONArray(str).getJSONObject(0).getString("message");

        if (!"0".equals(code)) {
            throw new Exception("创建失败"+message);
        }
        return new JSONArray(str).getJSONObject(0).getString("objectid");
    }

    private MultiValueMap Data(String name,String begDate, String endDate, String putQty,String getQty) {

        HashMap params = new HashMap();

        params.put("ACTIVITY_NAME","'"+name+"'");
        params.put("DATE_BEGIN","'"+begDate+"'");	//VIP类型
        params.put("DATE_END","'"+endDate+"'");//	经销商
        params.put("PUT_QTY","'"+putQty+"'");	//开卡店仓
        params.put("GET_QTY","'"+getQty+"'");//	手机


        params.put("table", "L_MARKETINGACTIVITIES");//表名

        return DATA("ObjectCreate", params, account, password);
    }

    public static void main(String[] args) {
        createMarketingVO g = new createMarketingVO("8.130.161.41:55321", "nea@burgeon.com.cn", "burgeon55321");
        try {
            System.err.println( g.getData("测试","20201203","20201205","10","0")
);
           //            VipAttrib vipAttrib = new VipAttrib();
//            vipAttrib.setVipAttrib2("120-140");
//            g.getData("17732145129",vipAttrib);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
